<template>
	<view class="container">
		<view class="mtopbox" :style="'padding-top:'+top+'px;'" v-if="isshop==1">
			<view style="height: 94rpx;"></view>
			<view class="mtop" :style="'padding-top:'+top+'px;'">
				<navigator url="/pages/shoplist/shoplist" hover-class="none">
					<view class="topmap">
						<view class="iconfont icon-icon-GIS_dizhi"></view>{{shop.name}}<text></text>
					</view>
				</navigator>
			</view>
		</view>
		<!-- 首页轮播图 -->
		<view class="banner">
			<swiper class="swiper" circular indicator-dots="true" indicator-color="rgba(255, 255, 255, .3)"
				indicator-active-color="#FFFFFF" autoplay="true" interval="5000" duration="500">
				<swiper-item v-for="(item,index) in banner" :key="index">
					<image :src="item.image" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- 首页分类 -->
		<view class="menu_link">
			<view class="menu_link_li" v-for="(item,index) in cates">
				<navigator :url="'/pages/sort/sort?cateid='+item.id" hover-class="none">
					<view class="menu_link_liimg">
						<image :src="item.image"></image>
					</view>
					<view class="menu_link_litxt">{{item.name}}</view>
				</navigator>
			</view>
			<!-- <view class="menu_link_li">
				<div @tap="zcfbbtn()" hover-class="none">
					<view class="menu_link_liimg">
						<image src="/static/images/mico1.png"></image>
					</view>
					<view class="menu_link_litxt">政策法规</view>
				</div>
			</view> -->
		</view>
		<view class="content pad30 adbanner" v-if="zhuanfa.homeimg">
			<navigator url="/pages/coupon/coupon" hover-class="none">
				<image :src="zhuanfa.homeimg" mode="widthFix"></image>
			</navigator>
		</view>
		<!-- <view class="content pad30 mgt40">
			<view class="ctitlebox">
				<view class="ctitle">热门项目</view>
				<view class="imore" @tap="xmbtn()">查看更多<text></text></view>
			</view>
			<view class="goods">
				<view class="goods_li" v-for="(item,index) in homepro" :key="index">
					<navigator :url="'/pages/goodsdetail/goodsdetail?id='+item.id" hover-class="none">
						<view class="goods_img">
							<image :src="item.image" mode="aspectFill"></image>
						</view>
						<view class="goods_title">{{item.name}}</view>
						<view class="goods_price">￥{{item.price}}</view>
					</navigator>
				</view>
			</view>
		</view> -->
		<view class="content pad30 mgt40">
			<view class="ctitlebox">
				<view class="ctitle">会议室</view>
				<view class="imore" @tap="ysbtn()">查看更多<text></text></view>
			</view>
			<view class="hotys">
				<scroll-view class="hotysbox" scroll-x="true">
					<view class="hotysdl" v-for="(item,index) in doctor" :key="item.id">
						<navigator hover-class="none" :url="'/pages/doctordetail/doctordetail?id='+item.id">
							<view class="hotysdlbox">
								<view class="hotysdt">
									<image :src="item.avatar" mode="aspectFill"></image>
								</view>
								<view class="hotysdd">
									<view class="hotysdl_t"><text>{{item.name}}</text>
									<!--{{item.jibie}}-->
									</view>
									<view class="hotysdl_b">面积：{{item.area}}</view>
								</view>
							</view>
						</navigator>
					</view>

				</scroll-view>
			</view>
		</view>
		
		<view class="content pad30 mgt40" v-if="doctor1[0]">
			<view class="ctitlebox">
				<view class="ctitle">预约参观</view>
				<view class="imore" @tap="ysbtn()">查看更多<text></text></view>
			</view>
			<view class="hotys">
				<scroll-view class="hotysbox" scroll-x="true">
					<view class="hotysdl" v-for="(item,index) in doctor1" :key="item.id">
						<navigator hover-class="none" :url="'/pages/doctordetail/doctordetail?id='+item.id">
							<view class="hotysdlbox">
								<view class="hotysdt">
									<image :src="item.avatar" mode="aspectFill"></image>
								</view>
								<view class="hotysdd">
									<view class="hotysdl_t"><text>{{item.name}}</text>
									<!--{{item.jibie}}-->
									</view>
									<view class="hotysdl_b">面积：{{item.area}}</view>
								</view>
							</view>
						</navigator>
					</view>
		
				</scroll-view>
			</view>
		</view>
		
		<view class="content pad30 mgt40" v-if="doctor2[0]">
			<view class="ctitlebox">
				<view class="ctitle">茶水间</view>
				<view class="imore" @tap="ysbtn()">查看更多<text></text></view>
			</view>
			<view class="hotys">
				<scroll-view class="hotysbox" scroll-x="true">
					<view class="hotysdl" v-for="(item,index) in doctor2" :key="item.id">
						<navigator hover-class="none" :url="'/pages/doctordetail/doctordetail?id='+item.id">
							<view class="hotysdlbox">
								<view class="hotysdt">
									<image :src="item.avatar" mode="aspectFill"></image>
								</view>
								<view class="hotysdd">
									<view class="hotysdl_t"><text>{{item.name}}</text>
									<!--{{item.jibie}}-->
									</view>
									<view class="hotysdl_b">面积：{{item.area}}</view>
								</view>
							</view>
						</navigator>
					</view>
		
				</scroll-view>
			</view>
		</view>
		
		
		<!-- <view class="content pad30 mgt40">
			<view class="ctitlebox">
				<view class="ctitle">热门活动</view>
				<view class="imore" @tap="hdbtn()">查看更多<text></text></view>
			</view>
			<view class="hdlist">
				<view class="hdlist_li" v-for="(item,index) in promotion" :key="item.id">
					<navigator hover-class="none" :url="'/pages/goodsdetail/goodsdetail?hdid='+item.id">
						<view class="hdlist_img">
							<image :src="item.image" mode="aspectFill"></image>
						</view>
						<view class="hdlist_title">{{item.name}}</view>
						<view class="hdlist_bot">
							<view class="hdlist_time">有效期：{{item.start}}至{{item.end}}</view>
							<view class="hdlist_state">{{item.txt}}</view>
						</view>
					</navigator>
				</view>
			</view>
		</view> -->
		<view class="content pad30 mgt40">
			<view class="ctitlebox">
				<view class="ctitle">园区新闻</view>
				<view class="imore" @tap="noticebtn()">查看更多<text></text></view>
			</view>
			<view class="hdlist">
				<view class="hdlist_li" v-for="(item,index) in notice" :key="item.id">
					<navigator hover-class="none" :url="'/pages/goodsdetail/goodsdetail?id='+item.id">
						<view class="hdlist_title">{{item.name}}</view>
						<view class="hdlist_bot">
							<view class="hdlist_time">{{item.desc}}</view>
							<view class="hdlist_state">{{item.createtime_text}}</view>
						</view>
					</navigator>
				</view>
			</view>
		</view>
	</view>
	<!--核销成功弹窗-->
	<view class="writeoff_bg" @click="hideModal" v-if="showModal"></view>
	<view class="writeoff_pop" v-if="showModal">
		<view class="writeoff_box">
			<view class="writeoff_ico">
				<image src="/static/images/yesico.png"></image><text>核销成功</text>
			</view>
			<view class="writeoff_goods">
				<view class="writeoff_goods_img">
					<image src="/static/images/proimg.jpg" mode="aspectFill"></image>
				</view>
				<view class="writeoff_goods_title">{{order}}</view>
				<view class="writeoff_goods_num">x1</view>
			</view>
			<view class="writeoff_tis">已放置在核销订单</view>
			<view class="writeoff_btn">
				<navigator hover-class="none" url="/pages/user/hxorder/hxorder">立即查看</navigator>
			</view>
			<view class="writeoff_close" @click="hideModal"><text></text></view>
		</view>
	</view>
	<!--核销成功弹窗end-->
</template>

<script>
	import API from "@/common/api.js";
	//#ifdef WEB
	import jweixin from 'weixin-js-sdk'
	//#endif
	export default {
		data() {
			return {
				top: "",
				bottom: "",
				title: '',
				showModal: false,
				order: "",
				banner: [],
				cates: [],
				homepro: [],
				doctor: [],
				doctor1: [],
				doctor2: [],
				promotion: [],
				notice: [],
				zhuanfa: [],
				shop: [],
				isshop: API.isshop
			}
		},
		//#ifdef MP-WEIXIN
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: this.zhuanfa.zftitle,
				path: '/pages/index/index',
				imageUrl: this.zhuanfa.zfimg
			}
		},
		onShareTimeline(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: this.zhuanfa.zftitle,
				path: '/pages/index/index',
				imageUrl: this.zhuanfa.zfimg
			}
		},
		//#endif
		onLoad(options) {
			var pscene = 0;
			//#ifdef MP-WEIXIN
			var param = uni.getLaunchOptionsSync()
			pscene = param.scene
			//#endif
			this.top = getApp().globalData.top
			var $this = this

			//判断是否确定过门店 多门店开启的情况
			var shopid = uni.getStorageSync("shopid");
			if (pscene != 1154) {
				if (this.isshop == 1) {
					if (!shopid) {
						uni.redirectTo({
							url: "/pages/shoplist/shoplist"
						})
					} else {
						API.post("common/getshop", {
							id: shopid
						}).then((res) => {
							if (res.code == 1) {
								$this.shop = res.data
							} else {
								uni.redirectTo({
									url: "/pages/shoplist/shoplist"
								})
							}
						})
					}
				}
			}


			API.post("banner/getBanner").then((res) => {
				if (res.code == 1) {
					$this.banner = res.data
				}
			})
			API.post("product/homeCate").then((res) => {
				if (res.code == 1) {
					$this.cates = res.data
				}
			})
			API.post("product/homepro", {
				isshop: this.isshop,
				shopid: shopid,
				scene: pscene
			}).then((res) => {
				if (res.code == 1) {
					$this.homepro = res.data
				}
			})
			//会议室
			API.post("doctor/homeDoctor", {
				// isshop: this.isshop,
				isshop: 3,
				// shopid: shopid,
				shopid: 3,
				scene: pscene
			}).then((res) => {
				if (res.code == 1) {
					$this.doctor = res.data
				}
			})
			//展厅
			API.post("doctor/homeDoctor", {
				// isshop: this.isshop,
				isshop: 4,
				// shopid: shopid,
				shopid: 4,
				scene: pscene
			}).then((res) => {
				if (res.code == 1) {
					$this.doctor1 = res.data
				}
			})
			//茶水间
			API.post("doctor/homeDoctor", {
				// isshop: this.isshop,
				isshop: 2,
				// shopid: shopid,
				shopid: 2,
				scene: pscene
			}).then((res) => {
				if (res.code == 1) {
					$this.doctor2 = res.data
				}
			})
			
			API.post("common/homePromotion", {
				isshop: this.isshop,
				shopid: shopid,
				scene: pscene
			}).then((res) => {
				if (res.code == 1) {
					$this.promotion = res.data
				}
			})
			//园区新闻
			API.post("common/indexnotice", {
				isshop: this.isshop,
				shopid: shopid,
				scene: pscene
			}).then((res) => {
				if (res.code == 1) {
					$this.notice = res.data
				}
			})
			API.post("common/zhuanfa").then((res) => {
				if (res.code == 1) {
					$this.zhuanfa = res.data
				}
			})
			//优惠券核销和订单核销
			var scene = this.parseScene(decodeURIComponent(options.scene))
			if (scene.couponid != undefined) {
				API.post("common/couponHexiao", {
					id: scene.couponid
				}).then((res) => {
					if (res.code == 1) {
						API.showModal(res.msg)
					} else {
						API.showModal(res.msg)
					}
				})
			}
			if (scene.orderid != undefined) {
				API.post("common/orderHexiao", {
					id: scene.orderid
				}).then((res) => {
					if (res.code == 1) {
						$this.order = res.data
						API.showModal(res.msg)
					} else {
						API.showModal(res.msg)
					}
				})
			}
			//公众号分享
			//#ifdef WEB
			var surl = encodeURIComponent(window.location.href.split('#')[0]);
			API.post("common/jweixin", {
				surl: surl
			}).then((res) => {
				if (res.code == 1) {
					jweixin.config({
						debug: res.data.debug,
						appId: res.data.appId,
						timestamp: res.data.timestamp,
						nonceStr: res.data.nonceStr,
						signature: res.data.signature,
						surl: res.data.url,
						jsApiList: res.data.jsApiList
					});

					jweixin.ready(function() {
						jweixin.updateAppMessageShareData({
							title: res.data.zftitle,
							desc: res.data.zfdesc,
							link: surl,
							imgUrl: res.data.zfimg,
							success: function() {
								console.log('分享到朋友圈成功');
							},
						});
						jweixin.updateTimelineShareData({
							title: res.data.zftitle,
							link: surl,
							imgUrl: res.data.zfimg,
							success: function() {
								console.log('分享到朋友圈成功');
							},

						});
					});

				}
			})
			//#endif
		},
		methods: {
			hideModal() {
				this.showModal = false
			},
			parseScene(scene) {
				var params = new Object();
				var scene = decodeURIComponent(scene).split('&');
				for (var i = 0; i < scene.length; i++) {
					params[scene[i].split('=')[0]] = scene[i].split('=')[1];
				}
				return params;
			},
			xmbtn() {
				uni.navigateTo({
					url: '/pages/sort/sort'
				})
			},
			zcfbbtn() {
				uni.switchTab({
					url: '/pages/policy/policys'
				})
			},
			ysbtn() {
				uni.switchTab({
					url: '/pages/doctor/doctor'
				})
			},
			hdbtn() {
				uni.navigateTo({
					url: '/pages/activity/activity'
				})
			},
			noticebtn() {
				uni.navigateTo({
					url: '/pages/user/gonggao/gonggao'
				})
			},
		}
	}
</script>

<style lang="scss">
	@import '@/static/style.css';

	.container {
		padding-bottom: 30rpx;
	}

	.swiper {
		width: 100%;
		height: 400rpx;
	}

	.swiper image {
		width: 100%;
		height: 100%;
	}

	.menu_link {
		width: 100%;
		overflow: hidden;
	}

	.menu_link_li {
		// width: 20%;
		width: 25%;
		float: left;
		text-align: center;
		margin-top: 40rpx;
	}

	.menu_link_li image {
		width: 80rpx;
		height: 80rpx;
	}

	.menu_link_litxt {
		height: 40rpx;
		line-height: 40rpx;
		margin-top: 10rpx;
		font-size: 28rpx;
	}

	.adbanner {
		margin-top: 40rpx;
	}

	.adbanner image {
		width: 100%;
	}

	.writeoff_bg {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		background: #000;
		opacity: 0.5;
		overflow: hidden;
		z-index: 999;
		color: #fff;
	}

	.writeoff_pop {
		width: 80%;
		border-radius: 40rpx 40rpx 0 0;
		position: fixed;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		z-index: 10000;
	}

	.writeoff_box {
		width: 100%;
		background: #fff;
		border-radius: 20rpx;
		padding: 60rpx 30rpx;
		box-sizing: border-box;
		position: relative;
		z-index: 2;
	}

	.writeoff_box::after {
		content: '';
		position: absolute;
		top: 4rpx;
		left: 0;
		right: 0;
		height: 300rpx;
		background: linear-gradient(to bottom, #dcecff, #fff);
		z-index: -1;
		border-radius: 20rpx;
	}

	.writeoff_close {
		width: 40rpx;
		height: 40rpx;
		border-radius: 80rpx;
		border: 4rpx #c0c0c0 solid;
		position: absolute;
		left: 50%;
		bottom: -120rpx;
		transform: translateX(-50%);
		padding: 20rpx;
	}

	.writeoff_close text {
		display: block;
		transform: rotate(45deg);
		width: 100%;
		height: 100%;
		position: relative;
	}

	.writeoff_close text::after,
	.writeoff_close text::before {
		content: '';
		background: #c0c0c0;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
	}

	.writeoff_close text::after {
		width: 100%;
		height: 4rpx;
	}

	.writeoff_close text::before {
		width: 4rpx;
		height: 100%;
	}

	.writeoff_ico {
		text-align: center;
	}

	.writeoff_ico image {
		width: 236rpx;
		height: 128rpx;
	}

	.writeoff_ico text {
		display: block;
		font-size: 36rpx;
		font-weight: bold;
		padding-top: 30rpx;
		color: #333;
	}

	.writeoff_tis {
		color: #888;
		font-size: 26rpx;
		margin-top: 30rpx;
		text-align: center;
	}

	.writeoff_btn {
		width: 70%;
		height: 80rpx;
		line-height: 80rpx;
		border-radius: 80rpx;
		background: $color;
		color: #fff;
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
		margin: 50rpx auto 0;
	}

	.writeoff_goods {
		width: 100%;
		background: #f7f7f7;
		border-radius: 12rpx;
		padding: 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		margin-top: 40rpx;
	}

	.writeoff_goods_img {
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
		overflow: hidden;
		margin-right: 20rpx;
	}

	.writeoff_goods_img image {
		width: 100%;
		height: 100%;
	}

	.writeoff_goods_title {
		flex: 1;
		font-size: 28rpx;
		color: #333;
	}

	.writeoff_goods_num {
		color: #888;
		font-size: 26rpx;
		margin-left: 30rpx;
	}
</style>